<?php
Abstract class ProcessingDate{
	
	public function __set($name, $value) {		
		//Seta os dados do mapeamento do banco.
		if($this->fieldsDB[$name] != "")
			$this->fieldsDBObj[$this->fieldsDB[$name]] = $value;

		//Seta o atributo.
		if($name == "id"){
			$this->setId($value);
		}else{
			$this->$name = $value;
		}
	}
	
	public function setId($id){
		if(!isset($this->id))
			$this->id = (int)$id;
		else
			$this->setDefaultError();
	}
	
	//Faz o mapeamento do banco para classe
	public function setDadosDB($obj){
		if(count($obj) > 0){
			foreach($this->fieldsDB as $key => $field){				
				$this->$key = $obj->$field;
				$obj->$field = null;
			}

			foreach($obj as $key => $value){
				if($value != null){
					$this->$key = $value;
				}
			}
		}
	}

	/*GET METODOS*/
	public function __get($name) {		
		if($name == "id"){
			return $this->getId();
		}else{
			return $this->$name;
		}
	}

	public function getId(){
		if(isset($this->id))
			return (int)$this->id;
		else
			return NULL;
	}

	public function getParamArray(){
		if(count($this->fieldsDB) > 0){
			$return = null;
			foreach($this->fieldsDB as $key => $row){
				$return[$key] = $this->$key;
			}
		}

		return $return;
	}

}
?>